var root={};
root.manage={};

/*article*/
root.manage.article={};
root.manage.article.init=function(options){
	root.manage.article.getChannelList(options);
	root.manage.article.changeChannel();
	root.manage.article.initGrid();
};
root.manage.article.getChannelList = function(options){
    var typeid_url = options.ctx+"/manage/channel/getJson.jspx?format=json&cattype=2&pageable=false";
    $.get(typeid_url,function(data){
        var $select_object = $("#"+options.select_id);
        $select_object.empty();
        $select_object.append('<option value="0" selected>请选择类别</option>');
        $.each(data.datarows,function(index,element){
            $select_object.append('<option value="'+element.id+'">'+element.name+'</option>');
        });
        if(channelId!==undefined && channelId>-1) {
            $select_object.val(channelId);
        }
    });
};
root.manage.article.changeChannel = function(){
	$("#channelId").change(function(){
		var channel_id = typeid_select.find("option:selected").val();
		root.customGrid.reload({url:"getJson.jspx?format=json&channelid="+channel_id});
	});
};
root.manage.article.initGrid=function(){
	var options={}
	,colNames = ["","序号","栏目","标题","点击数","添加时间"]
	,colModel = [
			{name:"myac",index:"myac",fixed:true,width:80,formatter:customActions,formatoptions:{
			keys:false,
			editformbutton:false,
			editUrl:"preEdit.jspx?id=",
			delUrl:"delete.jspx",
			seachable:false
			}},
			{name:"id",index:"id",width:15,key:true},
			{name:"channel.name",index:"channel.name",width:40},
			{name:"title",index:"title",width:80},
			{name:"hits",index:"hits",width:25},
			{name:"addtime",index:"addtime",width:35}
		];
	options={
			caption:"文章管理"
			,colNames:colNames
			,colModel:colModel
			,newUrl:"preAdd.jspx"
			,editUrl:"preEdit.jspx?id="
			,delUrl:"delete.jspx"
	};
	root.customGrid.init(options);
};
root.manage.article.openLinkurl = function(show){
    if(show==1){
        $("#linkurl-div").css("display","block");
        $("#upload2").css("display","block");
        root.customUploader.uploadFiles.init("linkurl","upload2");
    }else{
        $("#linkurl-div").css("display","none");
        $("#upload2").css("display","none");
        root.customUploader.uploadFiles.destory("upload2");
    }
};
root.manage.article.edit={};
root.manage.article.edit.init=function(options){
	if(options!==undefined && options.isEdit==true){
		root.manage.article.openLinkurl(options.linktype);
		UE.getEditor("summary_container");
		UE.getEditor("content_container");
		root.manage.article.validate();
		root.manage.article.getChannelList(options);
		
		$(":input[name='istop'][value="+options.istop+"]").attr("checked",true);
		$(":input[name='linktype'][value="+options.linktype+"]").attr("checked",true);
	}else{
		root.manage.article.openLinkurl(0);
		UE.getEditor("summary_container");
		UE.getEditor("content_container");
		root.manage.article.validate();
		root.manage.article.getChannelList({ctx:options.ctx,select_id:"channelId",channelId:-1});
	}
};

/*Channel*/
root.manage.channel={};
root.manage.channel.init=function(){
	root.manage.channel.getChannelTree();
	root.manage.channel.initGrid();
};
root.manage.channel.getChannelTree = function(){
    $.get("getChannelTree.jspx?format=json",function(data){
        var settings = {
            data:{
                simpleData:{
                    enable:true
                }
            },
            callback:{
                onClick:onClick
            }
        };
        var nodes = data.ztree;
        $.fn.zTree.init($("#channel-tree"),settings,nodes);
    });

    function onClick(event, treeId, treeNode, clickFlag){
        var id = treeNode.id;
        var isParent = treeNode.isParent;
        var url = "getChannels.jspx?id="+id;
        if(isParent){
            root.customGrid.changeCaption({name:treeNode.name});
            root.customGrid.reload({url:url});
        }
        else{
            location.href="preEdit.jspx?id="+id;
        }
    };
};
root.manage.channel.getParentChannelsTree = function(){
    var parentChannelObject = $("#parentChannel");
    var offset = parentChannelObject.offset();
    $("#channelContent").css({left:offset.left+"px", top:offset.top + parentChannelObject.outerHeight()+"px" }).slideDown("fast");

    $.get("getChannelTree.jspx?type=1&format=json",function(data){
        var settings = {
            data:{
                simpleData:{
                    enable:true
                }
            },
            callback:{
                onClick:onClick
            }
        };
        var nodes = data.ztree;
        $.fn.zTree.init($("#treeChannels"),settings,nodes);
    });
    function onClick(event, treeId, treeNode, clickFlag){
        var id = treeNode.id;
        $("#parentid").val(id);
        $("#parentChannel").val(treeNode.name);
        $("#channelContent").fadeOut("fast");
    }
};
root.manage.channel.initGrid= function(parentId,url,rowNum){
    var options={};
    var colNames = ["","序号","名称","点击数","排序号","添加时间","修改时间"];
    var colModel = [
        {name:"myac",fixed:true,width:55,formatter:customActions,formatoptions:{
            keys:true,
            editformbutton:false,
            editUrl:"preEdit.jspx?id=",
            delUrl:"delete.jspx?id="}
        },
        {name:"id",index:"id",width:10,key:true},
        {name:"name",index:"name",width:60},
        {name:"hits",index:"hits",width:25},
        {name:"orderid",index:"orderid",width:20},
        {name:"addtime",index:"addtime",width:35},
        {name:"edittime",index:"edittime",width:35}
    ];
    options = {
    		colNames:colNames
    		,colModel:colModel
    		,caption:"栏目管理"
    		,url:"getChannels.jspx?format=json"
    	    ,newUrl:"preAdd.jspx"
    	    ,editUrl:"preEdit.jspx?id="
    	    ,delUrl:"del.jspx"
    };
    root.customGrid.init(options);
};
/*用于在preEdit和preAdd中修改Channel的内部链接和外部链接时使用*/
root.manage.channel.changeChannelType = function(channelType){
    if(channelType==0){
        $("#div_linkurl").css("display","none");
        $("#div_shortdesc").css("display","block");
        $("#div_description").css("display","block");

        $("#upload2").css("display","none");
        root.customUploader.uploadFiles.destory("linkurl","upload2");
    }else if(channelType==1){
        $("#div_linkurl").css("display","none");
        $("#div_shortdesc").css("display","none");
        $("#div_description").css("display","none");

        $("#upload2").css("display","none");
        root.customUploader.uploadFiles.destory("linkurl","upload2");
    }else if(channelType==2){
        $("#div_linkurl").css("display","none");
        $("#div_shortdesc").css("display","none");
        $("#div_description").css("display","none");

        $("#upload2").css("display","none");
        root.customUploader.uploadFiles.destory("linkurl","upload2");
    }else if(channelType==3){
        $("#div_linkurl").css("display","none");
        $("#div_shortdesc").css("display","block");
        $("#div_description").css("display","block");

        $("#upload2").css("display","none");
        root.customUploader.uploadFiles.destory("linkurl","upload2");
    }else{
        $("#div_linkurl").css("display","block");
        $("#div_shortdesc").css("display","none");
        $("#div_description").css("display","none");

        $("#upload2").css("display","block");
        root.customUploader.uploadFiles.init("linkurl","upload2");
        $(".webuploader-container").css("position",null);
    }
};

root.manage.channel.edit={};
root.manage.channel.edit.init=function(options){
	if(options!==undefined && options.isEdit==true){
		root.manage.channel.changeChannelType(options.channelType);
		UE.getEditor("summary_container");
		UE.getEditor("content_container");
		
		root.manage.channel.validate();
		$(":input[name='type'][value='"+options.channelType+"']").attr("checked",true);
		$(":input[name='isopen'][value='"+options.isopen+"']").attr("checked",true);
		$(":input[name='inmenu'][value='"+options.inmenu+"']").attr("checked",true);
		
		$("#tempate_id").val(options.templateId);
	}else{
		
		root.manage.channel.changeChannelType(options.channelType);
		UE.getEditor("summary_container");
		UE.getEditor("content_container");
		
		root.manage.channel.validate();
	}
	$("#channelBtn").on("click",function(){
        root.manage.channel.getParentChannelsTree();
    });
};

root.manage.channel.sort={};
root.manage.channel.sort.init=function(){
	root.manage.channel.sort.getSortChannelTree();
	root.manage.channel.sort.reloadSortGrid(true,0);
	
	$("#saveOrderid").on("click",function(e){
		$("#sortForm").ajaxSubmit(function(data){
			if(data.success==1){
				root.manage.channel.sort.reloadSortGrid(data.isParent,data.current_id);
			}
		});
	});
};
root.manage.channel.sort.getSortChannelTree = function(){
    $.get("getChannelTree.jspx?format=json",function(data){
        var settings = {
            data:{
                simpleData:{
                    enable:true
                }
            },
            callback:{
                onClick:onClick
            }
        };
        var nodes = data.ztree;
        $.fn.zTree.init($("#channel-tree"),settings,nodes);
    });

    function onClick(event, treeId, treeNode, clickFlag){
        var id = treeNode.id;
        var isParent = treeNode.isParent;
        
        root.manage.channel.sort.reloadSortGrid(isParent,id);
        
    };
};

root.manage.channel.sort.reloadSortGrid = function(isParent,id){
	var url = "getChannels.jspx?format=json&pageable=false&id="+id;
	if(isParent){
		url = "getChannels.jspx?format=json&pageable=false&id="+id;
	}else{
		url = "getChannels.jspx?format=json&action=get&id="+id;
	}
	
	$("#isParent").val(isParent);
	$("#current_id").val(id);
	
	$.get(url,function(data){
		var datarows = data.datarows;
		var gridTable = $("#gridTable");
		gridTable.find("tbody").empty();
		if(datarows!=undefined){
			$.each(datarows,function(index,element){
				var tr = $("<tr>");
				tr.append("<td>"+element.name+"</td>");
				tr.append("<td><input type='text' name='orderid_"+element.id+"' value='"+element.orderid+"'></td>");
				gridTable.append(tr);
			});
		}
	});
};

/*news*/
root.manage.news={};
root.manage.news.init=function(options){
	root.manage.news.initGrid();
	root.manage.news.getNewsChannels(options);
	root.manage.news.changeType();
};
root.manage.news.initGrid=function(){
	var colNames = ["","序号","类别","标题","作者","编辑","来源","点击数","添加时间"];
	var colModel = [
			{name:"myac",index:"myac",fixed:true,width:60,formatter:customActions,formatoptions:{
			keys:false,
			editformbutton:false,
			editUrl:"preEdit.jspx?id=",
			delUrl:"delete.jspx"
			}},
			{name:"id",index:"id",width:10,key:true,align:"center"},
			{name:"newsChannel.name",index:"newsChannel.name",width:20},
			{name:"title",index:"title",width:70},
			{name:"author",index:"author",width:15},
			{name:"inputer",index:"inputer",width:10},
			{name:"copyfrom",index:"copyfrom",width:15},
			{name:"hits",index:"hits",width:10,align:"center"},
			{name:"addtime",index:"addtime",width:25}
		];
	var options={colNames:colNames
			,colModel:colModel
			,newUrl:"preAdd.jspx"
			,editUrl:"preEdit.jspx?id="
			,delUrl:"delete.jspx"};
	root.customGrid.init(options);
};
root.manage.news.getNewsChannels = function(options){
    var typeid_url = options.ctx+"/manage/news_channel/getJson.jspx?format=json&pageable=false";
    $.get(typeid_url,function(data){
        var select_object = $("#"+options.select_id);
        select_object.empty();
        select_object.append('<option value="0">请选择类别</option>');
        $.each(data.datarows,function(index,element){
            select_object.append('<option value="'+element.id+'">'+element.name+'</option>');
        });
        if(options.newsChannelId!=-1) {
            select_object.val(options.newsChannelId);
        }
    });
};
root.manage.news.changeType = function(){
	var typeid_select = $("#newsChannelId");
	typeid_select.change(function(){
		var newsChannelId = typeid_select.find("option:selected").val();
		root.customGrid.reload({url:"getJson.jspx?format=json&newsChannelId="+newsChannelId});
	});
};

root.manage.news.edit={ctx:""};
root.manage.news.edit.init=function(options){
	root.manage.news.edit.openLinkurl(options.linktype);
	root.manage.news.edit.ctx=options.ctx;
	UE.getEditor("summary_container");
	UE.getEditor("content_container");
	
	root.manage.news.validate();
	root.manage.news.getNewsChannels(options);
	
	if(options!==undefined && options.isEdit==true){
		$(":input[name='istop'][value="+options.istop+"]").attr("checked",true);
		$(":input[name='linktype'][value="+options.linktype+"]").attr("checked",true);
	}
};
root.manage.news.edit.openLinkurl = function(show){
    if (show != 1) {
        $("#linkurl").css("display", "none");
        root.customUploader.uploadFiles.destory("upload2");
    } else {
        $("#linkurl").css("display", "block");
        root.customUploader.uploadFiles.init("linkurl", "upload2",root.manage.news.edit.ctx);
    }
};

/*news_channel*/
root.manage.newsChannel={};
root.manage.newsChannel.initGrid=function(){
	var colNames = ["","序号","名称","排序号","添加时间","修改时间","模板序号"];
	var colModel = [
			{name:"myac",fixed:true,width:80,formatter:"actions",formatoptions:{keys:true}},
			{name:"id",index:"id",width:35,key:true},
			{name:"name",index:"name",width:55,editable:true},
			{name:"orderid",index:"orderid",width:30,editable:true},
			{name:"addtime",index:"addtime",width:35,editable:false},
			{name:"edittime",index:"edittime",width:35,editable:false},
			{name:"templateId",index:"templateId",width:35,editable:false}
		];
	var options={
			caption:"新闻频道管理"
		,colNames:colNames
		,colModel:colModel
	};
	root.customGrid.init(options);
};

/*case*/
root.manage.caseCategory={};
root.manage.caseCategory.initGrid=function(){
	var colNames = ["","序号","名称","排序号"];
	var colModel = [
			{name:"myac",fixed:true,width:80,formatter:"actions",formatoptions:{keys:true}},
			{name:"id",index:"id",fixed:true,width:55,key:true},
			{name:"name",index:"name",width:55,editable:true},
			{name:"orderid",index:"orderid",width:30,editable:true}
		];
	var options={
			caption:"案例分类管理"
		,colNames:colNames
		,colModel:colModel
	};
	root.customGrid.init(options);
};

root.manage.cases={};
root.manage.cases.init=function(options){
	root.manage.cases.initGrid();
	root.manage.cases.getCategories(options);
};
root.manage.cases.initGrid=function(){
	var colNames = ["","序号","类别","标题","公司","输入","添加时间"];
	var colModel = [
			{name:"myac",index:"myac",fixed:true,width:60,formatter:customActions,formatoptions:{
			keys:false,
			editformbutton:false,
			editUrl:"preEdit.jspx?id=",
			delUrl:"delete.jspx"
			}},
			{name:"id",index:"id",width:10,key:true,align:"center"},
			{name:"category.name",index:"category",width:20},
			{name:"title",index:"title",width:50},
			{name:"company",index:"company",width:25},
			{name:"inputer",index:"inputer",width:10},
			{name:"addtime",index:"addtime",width:25}
		];
	var options={caption:"案例管理"
			,colNames:colNames
			,colModel:colModel
			,newUrl:"preAdd.jspx"
			,editUrl:"preEdit.jspx?id="
			,delUrl:"delete.jspx"};
	root.customGrid.init(options);
};
root.manage.cases.getCategories=function(options){
	var typeid_url = options.ctx+"/manage/case_category/getJson.jspx?format=json&pageable=false";
    $.get(typeid_url,function(data){
        var select_object = $("#"+options.select_id);
        select_object.empty();
        select_object.append('<option value="0">请选择类别</option>');
        $.each(data.datarows,function(index,element){
            select_object.append('<option value="'+element.id+'">'+element.name+'</option>');
        });
        if(options.currentCategoryId>-1) {
            select_object.val(options.currentCategoryId);
        }
    });
};

root.manage.cases.edit={};
root.manage.cases.edit.init=function(options){
	UE.getEditor("description_container");
	UE.getEditor("content_container");
	
	root.manage.cases.getCategories(options);
	root.customUploader.uploadFiles.init("thumb", "upload2",options.ctx);
};

/*product*/
root.manage.product={};
root.manage.product.init=function(options){
	root.manage.product.initGrid();
	root.manage.productCategory.getList({ctx:options.ctx,select_id:"categoryId",parentid:options.parentid,currentCategoryId:-1});
	
	$("#categoryId").on("change",function(){
		var value = $(this).val();
		root.manage.productCategory.getList({ctx:options.ctx,select_id:"primary_category",parentid:value,currentCategoryId:-1,isdefault:false});
	});
	
	$('#primary_category').on('change',function(){
		var value = $(this).val(),
		brandId = $('#brandId').val();
		root.customGrid.reload({url:'getJson.jspx?format=json&pageable=true&categoryId='+value+'&brandId='+brandId});
	});
	root.manage.productBrand.getList({ctx:options.ctx,select_id:"brandId",currentBrandId:-1});
	$('#brandId').on('change',function(){
		var value = $(this).val(),
		categoryId = $('#primary_category').val();
		root.customGrid.reload({url:'getJson.jspx?format=json&pageable=true&brandId='+value+'&categoryId='+categoryId});
	});
};
root.manage.product.initGrid=function(){
	var colNames = ["","序号","名称","品牌","类别","型号","添加时间","图片管理"];
	var colModel = [
			{name:"myac",index:"myac",fixed:true,width:60,formatter:customActions,formatoptions:{
			keys:false,
			editformbutton:false,
			editUrl:"preEdit.jspx?id=",
			delUrl:"delete.jspx"
			}},
			{name:"id",index:"id",width:55,fixed:true,key:true,align:"center"},
			{name:"name",index:"name",width:35},
			{name:"brand.name",index:"brand",width:25},
			{name:"category.name",index:"category",width:25},
			{name:"model",index:"model",width:25},
			{name:"addtime",index:"addtime",width:25},
			{name:"photos",index:"photos",width:25,align:"center",sortable:false,formatter:function(cellValue,options,rowObject){
				return '<a href="photoManage.jspx?id='+rowObject.id+'">图片管理</a>';
			}}
		];
	var options={caption:"产品管理"
			,colNames:colNames
			,colModel:colModel
			,newUrl:"preAdd.jspx"
			,editUrl:"preEdit.jspx?id="
			,delUrl:"delete.jspx"};
	root.customGrid.init(options);
	
	$('#gridTable_photos div').css('text-align','center');
};

root.manage.product.edit={};
root.manage.product.edit.init=function(options){
	UE.getEditor("description_container");
	root.customUploader.uploadFiles.init("photo","upload2",options.ctx);
	
	root.manage.productCategory.getList({ctx:options.ctx,select_id:"main_category",parentid:0,currentCategoryId:options.currentMainCategoryId,isdefault:false});
	
	$("#main_category").on("change",function(){
		var value = $(this).val();
		root.manage.productCategory.getList({ctx:options.ctx,select_id:"category",parentid:value,currentCategoryId:options.currentCategoryId,isdefault:false});
	});
	
	root.manage.productBrand.getList({ctx:options.ctx,select_id:"brandId",currentBrandId:options.currentBrandId});
	
	
};
root.manage.productCategory={};
root.manage.productCategory.init=function(options){
	root.manage.productCategory.initGrid();
	root.manage.productCategory.getList(options);
	
	$("#categoryId").on("change",function(){
		var value = $(this).val();
		var url = options.ctx+"/manage/product_category/getJson.jspx?format=json&pageable=false";
		if(value>-1){
			url += "&parentid="+value;
		}
		root.customGrid.reload({url:url});
	});
};
root.manage.productCategory.getList=function(options){
	var parentid = 0,isdefault=true;
	if(options===undefined || options.parentid===undefined){
		parentid = -1;
	}else{
		parentid = options.parentid;
	}
	if(options!==undefined && options.isdefault!==undefined){
		isdefault=options.isdefault;
	}
	$.get(options.ctx+"/manage/product_category/getJson.jspx?format=json&pageable=false",{parentid:parentid},function(data){
		if(data!==undefined && data!==null){
			var $selectObject = $("#"+options.select_id);
			if($selectObject!==undefined){
				$selectObject.empty();
				$selectObject.append("<option value='-1'>请选择</option>");
				if(isdefault){
					$selectObject.append("<option value='0'>一级分类</option>");
				}
				$.each(data.datarows,function(index,category){
					$selectObject.append("<option value='"+category.id+"'>"+category.name+"</option>");
				});

				if(options.currentCategoryId!==undefined && options.currentCategoryId>-1){
					$selectObject.val(options.currentCategoryId);
					$selectObject.change();
				}
			}
		}
	});
};
root.manage.productCategory.initGrid=function(){
	var colNames = ["","序号","父栏目","名称","排序号","添加时间"];
	var colModel = [
			{name:"myac",fixed:true,width:65,formatter:customActions,formatoptions:{
				keys:false,
				editformbutton:false,
				editUrl:"preEdit.jspx?id=",
				delUrl:"delete.jspx"
				}},
			{name:"id",index:"id",fixed:true,width:55,key:true},
			{name:"parent.name",index:"parent",width:25},
			{name:"name",index:"name",width:25},
			{name:"orderid",index:"orderid",width:10},
			{name:"addtime",index:"addtime",width:15}
		];
	var options={
			caption:"产品分类管理"
		,colNames:colNames
		,colModel:colModel
	    ,newUrl:"preAdd.jspx"
	    ,editUrl:"preEdit.jspx?id="
	    ,delUrl:"delete.jspx"
	};
	root.customGrid.init(options);
};
root.manage.productCategory.edit={};
root.manage.productCategory.edit.init=function(options){
	root.manage.productCategory.getList(options);
	root.manage.productCategory.validate();
};
root.manage.productBrand={};
root.manage.productBrand.initGrid=function(){
	var colNames = ["","序号","名称","国别","主页","图片名称","首页显示","排序号","添加时间"];
	var colModel = [
			{name:"myac",fixed:true,width:65,formatter:"actions",formatoptions:{keys:true}},
			{name:"id",index:"id",fixed:true,width:50,key:true,align:'center'},
			{name:"name",index:"name",width:30,editable:true},
			{name:"country",index:"country",width:15,editable:true},
			{name:"homepage",index:"homepage",width:30,editable:true},
		    {name:"logo",index:"logo",width:30,editable:true},
		    {name:"showIndex",index:"showIndex",align:"center",width:10,editable:false,formatter:function(cellValue,cellObject,rowObject){
		    	cellValue = (cellValue==0) ? 1 : 0;
		    	var result = '<a href="javascript:void(0)" onclick="root.manage.productBrand.changeStatus('+cellObject.rowId+','+cellValue+')">';;
		    	var text = "取消";
		    	if(cellValue==1){
		    		text = '<span style="color:green">设置</span>';
		    	}
		    	result = result + text + "</a>";
		    	console.log(result);
		    	return result;
		    }},
			{name:"orderid",index:"orderid",width:10,editable:true},
			{name:"addtime",index:"addtime",width:15}
		];
	var options={
			caption:"产品品牌管理"
		,colNames:colNames
		,colModel:colModel
	};
	root.customGrid.init(options);
};
root.manage.productBrand.changeStatus = function(id,value){
	$.get('changeStatus.jspx?format=json',{id:id,showIndex:value},function(data){
		if(data.hasError){
			alert(data.message);
		}else{
			root.customGrid.reloadSelf();
		}
	});
};
root.manage.productBrand.getList=function(options){
	$.get(options.ctx+"/manage/product_brand/getJson.jspx?format=json&pageable=false",function(data){
		if(data!==undefined && data!==null){
			var $selectObject = $("#"+options.select_id);
			$selectObject.empty();
			$selectObject.append("<option value='-1'>请选择品牌</option>");
			$.each(data.datarows,function(index,brand){
				$selectObject.append("<option value='"+brand.id+"'>"+brand.name+"</option>");
			});
			if(options!==undefined && options.currentBrandId>-1){
				$selectObject.val(options.currentBrandId);
			}
		}
	});
};

root.manage.config={};
root.manage.config.init=function(){
	root.manage.config.initGrid();
};
root.manage.config.initGrid=function(){
	var colNames = ["","序号","名称","当前主题","当前有效","关键词","添加时间"];
	var colModel = [
			{name:"myac",fixed:true,width:65,formatter:customActions,formatoptions:{
				keys:false,
				editformbutton:false,
				editUrl:"preEdit.jspx?id=",
				delUrl:"delete.jspx"
				}},
			{name:"id",index:"id",fixed:true,width:55,align:'center',key:true},
			{name:"webname",index:"webname",width:25},
			{name:"currentTheme",index:"currentTheme",width:10},
			{name:"isCurrent",index:"isCurrent",width:5},
			{name:"keywords",index:"keywords",width:15},
			{name:"addtime",index:"addtime",width:15}
		];
	var options={
			caption:"网站信息管理"
		,colNames:colNames
		,colModel:colModel
	    ,newUrl:"preAdd.jspx"
	    ,editUrl:"preEdit.jspx?id="
	    ,delUrl:"delete.jspx"
	};
	root.customGrid.init(options);
};
root.manage.config.edit={};
root.manage.config.edit.init=function(options){
	$(":input[name='isCurrent'][value='"+options.isCurrent+"']").attr("checked",true);
	
	UE.getEditor("webcopyright_container");
	
	root.manage.config.validate();
};

root.manage.photolink={};
root.manage.photolink.init=function(options){
	root.manage.photolink.initGrid();
	
	$("#category").on("change",function(){
		var category = $(this).val();
		root.customGrid.reload({url:"getJson.jspx?format=json&category="+category});
	});
};
root.manage.photolink.initGrid=function(){
	var colNames = ["","序号","名称","类别","标题","排序号","添加时间"];
	var colModel = [
			{name:"myac",fixed:true,width:65,formatter:customActions,formatoptions:{
				keys:false,
				editformbutton:false,
				editUrl:"preEdit.jspx?id=",
				delUrl:"delete.jspx"
				}},
			{name:"id",index:"id",fixed:true,width:55,align:'center',key:true},
			{name:"name",index:"name",width:25},
			{name:"category",index:"category",width:10},
			{name:"caption",index:"caption",width:25},
			{name:"orderid",index:"orderid",width:5},
			{name:"addtime",index:"addtime",width:15}
		];
	var options={
			caption:"图片导航管理"
		,colNames:colNames
		,colModel:colModel
	    ,newUrl:"preAdd.jspx"
	    ,editUrl:"preEdit.jspx?id="
	    ,delUrl:"delete.jspx"
	};
	root.customGrid.init(options);
};

root.manage.photolink.edit={};
root.manage.photolink.edit.init=function(options){
	root.customUploader.uploadFiles.init("imgUrl","imgUrl_upload",options.ctx);
	$(":input[name='category'][value='"+options.category+"']").attr("checked",true);
	root.manage.photolink.validate();
	
	UE.getEditor("content_container");
};

/*user*/
root.manage.user={};
root.manage.user.init=function(){
	root.manage.user.initGrid();
};
root.manage.user.initGrid=function(){
	var colNames = ["","序号","用户名","电话","锁定","删除","管理员","角色","添加时间"];
	var colModel = [
			{name:"myac",fixed:true,width:65,formatter:customActions,formatoptions:{
				keys:false,
				editformbutton:false,
				editUrl:"preEdit.jspx?id=",
				delUrl:"delete.jspx"
				}},
			{name:"id",index:"id",fixed:true,width:55,align:'center',key:true},
			{name:"username",index:"username",width:15},
			{name:"mobilePhone",index:"mobilePhone",width:15},
			{name:"blocked",index:"blocked",width:10},
			{name:"deleted",index:"deleted",width:5},
			{name:"admin",index:"admin",width:5},
			{name:"roleIds",index:"roleIds",width:15},
			{name:"addtime",index:"addtime",width:15}
		];
	var options={
			caption:"用户管理"
		,colNames:colNames
		,colModel:colModel
	    ,newUrl:"preAdd.jspx"
	    ,editUrl:"preEdit.jspx?id="
	    ,delUrl:"delete.jspx"
	};
	root.customGrid.init(options);
};
root.manage.user.edit={};
root.manage.user.edit.init=function(options){
	if(options!==undefined && options.isEdit===true){
		$("input[name='blocked'][value='"+options.blocked+"']").attr("checked",true);
		$("input[name='deleted'][value='"+options.deleted+"']").attr("checked",true);
		$("input[name='admin'][value='"+options.admin+"']").attr("checked",true);
		if(options.roleIds!==undefined && options.roldIds!==null){
		    var roleIds = options.roleIds.split(",");
		    $.each(roleIds,function(index,roleId){
		    	$("input[name='roleIds'][value='"+roleId+"']").attr("checked",true);
		    });
		}
		root.manage.user.validate();
	}else{
		root.manage.user.validate();
	}
};
root.manage.role={};
root.manage.role.initGrid=function(){
	var options = {};
    var colNames = ["","序号","名称","首页地址","添加时间"];
    var colModel = [
        {name:"myac",fixed:true,width:80,formatter:customActions,formatoptions:{keys:true
        	,editformbutton:false,
	        editUrl:"preEdit.jspx?id=",
	        delUrl:"delete.jspx?id="}},
        {name:"id",index:"id",width:10,key:true},
        {name:"name",index:"name",width:35,editable:true},
        {name:"index",index:"index",width:25,editable:true},
        {name:"addtime",index:"addtime",width:30,editable:true}
    ];
    options = {colNames:colNames,
               colModel:colModel,
               newUrl:"preAdd.jspx",
	           editUrl:"preEdit.jspx?id=",
	           delUrl:"del.jspx?id=",
               caption:"角色信息列表"};
    
    root.customGrid.init(options);
};
root.manage.role.getPermission=function(roleid){
	if(roleid>0){
		$.get("getPermission.jspx",{format:"json",id:roleid},function(data){
			if(data!==undefined && data!==null){
				var permissions = data.permissions;
				if(permissions===undefined || permissions===null){
					return;
				}
				$.each(permissions,function(index,permission){
					var resourceid = permission.resourceId;
					$(":input[name='resourceIds'][value='"+resourceid+"']").attr("checked",true);
					var permissionIds = permission.permissionIds;
					if(permissionIds!==undefined && permissionIds!==null){
						$.each(permissionIds.split(","),function(index,permissionId){
							$(":input[name='permission_"+resourceid+"'][value='"+permissionId+"']").attr("checked",true);
						});
					}
					
				});
			}
		});
	}
};

/*resource*/
root.manage.resource={};
root.manage.resource.init=function(){
	root.manage.resource.initGrid();
};
root.manage.resource.initGrid=function(){
	var options = {}
    ,colNames = ["","序号","名称","上一级","权限标识","有效","添加时间"]
    ,colModel = [
	    {name:"myac",fixed:true,width:80,formatter:customActions,formatoptions:{
	        keys:true,
	        editformbutton:false,
	        editUrl:"preEdit.jspx?id=",
	        delUrl:"delete.jspx?id="}
	    },
	    {name:"id",index:"id",width:10,key:true},
	    {name:"name",index:"name",width:35,editable:true},
	    {name:"parentid",index:"parentid",width:25,editable:true},
	    {name:"identity",index:"identity",width:25},
	    {name:"available",index:"available",width:30},
	    {name:"addtime",index:"addtime",width:25}
	];
	options = {colNames:colNames,
	           colModel:colModel,
	           newUrl:"preAdd.jspx",
	           editUrl:"preEdit.jspx?id=",
	           delUrl:"del.jspx?id=",
	           canEdit:true,
	           canAdd:true,
	           canDel:true,
	           caption:"资源列表"};
	
	root.customGrid.init(options);
};
root.manage.resource.edit={};
root.manage.resource.edit.init=function(options){
	root.manage.resource.validate();
	$("#parentid").val(options.parentid);
	$("input[name='avaliable'][value='"+options.available+"']").attr("checked",true);
};